package com.hula.onion.book.server.controller;

import com.hula.onion.book.server.common.CommonResponse;
import com.hula.onion.book.server.service.AccountInfoService;
import com.hula.onion.book.server.service.PlatformInfoService;
import com.hula.onion.book.server.service.PushMsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by shan on 18/1/24.
 */
@RestController
@RequestMapping("/onion-book/api/v1/platform")
@Api(value = "用户账户相关")
public class PlatformInfoController {

    @Autowired
    private PlatformInfoService platformInfoService;
    @Autowired
    private AccountInfoService accountInfoService;
    @Autowired
    private PushMsgService pushMsgService;

    @ApiOperation(value = "查询系统平台列表")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "platformName", value = "平台名称", dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String getPlatformList(@RequestParam(value = "platformName", required = false) String platformName) {
        return platformInfoService.getPlatformList(platformName);
    }

    @ApiOperation(value = "用户平台账户列表信息")
    @RequestMapping(value = "/userAccount", method = RequestMethod.GET)
    public CommonResponse getUserAccount(@RequestParam int userId) {
        return accountInfoService.getUserAccount(userId);
    }

    @ApiOperation(value = "平台账户详情信息")
    @RequestMapping(value = "/userPlatformAccount", method = RequestMethod.GET)
    public CommonResponse getUserPlatformAccount(@RequestParam int platformId, @RequestParam int investId) {
        return accountInfoService.getUserPlatformAccount(platformId, investId);
    }

    @ApiOperation(value = "平台账户chart图/列表(type:1-按平台;2-按周期;3-按利率)")
    @RequestMapping(value = "/userPlatformAccountChart", method = RequestMethod.GET)
    public CommonResponse userPlatformAccountChart(@RequestParam int userId, @RequestParam(value = "type", required = false, defaultValue = "0") int type) {
        return accountInfoService.userPlatformAccountChart(userId, type);
    }

    @ApiOperation(value = "发现中新闻列表")
    @RequestMapping(value = "/discover/news", method = RequestMethod.GET)
    public CommonResponse getNewsList(@RequestParam int page, @RequestParam int size) {
        return platformInfoService.getNewsList(page, size);
    }

    @ApiOperation(value = "获取新闻详情")
    @RequestMapping(value = "/get/news/detail", method = RequestMethod.GET)
    public CommonResponse getNewsDetail(@RequestParam int newsId) {
        return platformInfoService.getNewsDetail(newsId);
    }

    @ApiOperation(value = "消息列表")
    @RequestMapping(value = "/get/push/msg", method = RequestMethod.GET)
    public CommonResponse getPushMsgList(@RequestParam int userId, @RequestParam int page, @RequestParam int size) {
        return pushMsgService.getPushMsgList(userId, page, size);
    }

    @ApiOperation(value = "获取消息详情")
    @RequestMapping(value = "/get/push/msg/detail", method = RequestMethod.GET)
    public CommonResponse getPushMsgDetail(@RequestParam int msgId) {
        return pushMsgService.getPushMsgInfo(msgId);
    }

    @ApiOperation(value = "更新消息为已读")
    @RequestMapping(value = "/update/push/msg", method = RequestMethod.POST)
    public CommonResponse updatePushMsgStatus(@RequestParam int msgId) {
        return pushMsgService.updatePushMsgStatus(msgId);
    }

    @ApiOperation(value = "获取分享信息接口")
    @RequestMapping(value = "/share", method = RequestMethod.GET)
    public CommonResponse share() {
        Map<String, String> result = new HashMap<>();
        result.put("title", "合格羊毛的必备记账工具");
        result.put("content", "一键记账，自动同步账单，多平台投资一目了然。再也没有资金站岗的烦恼！");
        result.put("openUrl", "http://static.hulaup.com/ych5/download.html");
        result.put("downloadUrl", "http://t.cn/Rn84TeI");
        return new CommonResponse(result);
    }


    @ApiOperation(value = "获取版本信息")
    @RequestMapping(value = "/get/versionInfo", method = RequestMethod.POST)
    public CommonResponse getVersionInfo() {
        Map<String, String> result = new HashMap<>();
        result.put("version", "1.0.0");
        result.put("forceUpdate", "false");
        result.put("online", "true");
        result.put("downloadUrl", "");
        return new CommonResponse(result);
    }

}
